import apiMixin from '@/mixin/apiMixin';
import taskMixin from '@/mixin/taskMixin';

export default {
    mixins: [apiMixin,taskMixin],
    data() {
        return {
            showHandle:false,
            successShow:false,
            list: [],
            images:[],//图片预览的临时数组
            showBtn:false,
            page: 1,
            allowInfinite: true,
            searchTypeList: [
                { value: "user_id", name: "用户ID" },
                { value: "task_id", name: "任务ID" },
                { value: "task_accept_id", name: "任务接单ID" },
            ],
            searchType: 'user_id',
            searchText: '',
            hasMore: true
        }
    },
    mounted() {

    },
    methods: {
        getData(){
            let _this = this;
            console.log("触发了流加载");
            if (!this.allowInfinite) {
                return;
            }
            this.allowInfinite = false;
            this.getUploadFileListApi();
        },
        lookImage(index){//查看图片
            //this.$viewer.show();
            this.getImgListApi(index);
        },
        inited (viewer) {//初始化预览图片组件
            this.$viewer = viewer;
            this.$viewer.view(0);
        },
        select(index){
            let item = this.list;
            if(item[index].status==0){
                this.images = [];
                item[index].select = !item[index].select;
    
                this.checkAll();
            }else{
                this.$notify.error({title: '错误',message: '此条任务不是待审核状态，无法勾选。'});
            }
        },
        checkAll(){//检查是否有勾选状态的,并返回数组ID值。
            let _this = this;
            let ids = [];
            for(var i in _this.list){
                if(_this.list[i].select){
                    ids.push(_this.list[i].id);
                }
            }
    
            if(ids.length>0){
                this.showBtn = true;
            }else{
                this.showBtn = false;
            }
            return ids;
        },
        getUploadFileListApi() {
            let _self = this;
            this.comResquest(this.request.getUploadFileList,(res)=>{
                let { count,result,pagesize,page } = res;
                _self.updateRoutePar();
                if (this.page > 1) {
                    _self.list = _self.list.concat(result);
                }else{
                    _self.list = result;
                }
                if (count >= page * pagesize) {
                    _self.page = _self.page + 1;
                    _self.allowInfinite = true;
                }else{
                    _self.hasMore = false;
                }
            },{
                page: this.page,
                type: this.searchType,
                keyword: this.searchText,
            })
        },
        handleSearch() {
            this.page = 1;
            this.getUploadFileListApi();
        },
        getImgListApi(lookIndex) {
            let _self = this;
            this.comResquest(this.request.getUploadFileList,(res)=>{
                console.log(res);
                let images = [];
                let { result } = res;
                result.map((item)=>{
                    images.push(item.url);
                });
                _self.images = images;
                _self.$viewer.show();
            },{
                load: true,
                type: 'task_accept_id',
                keyword: this.list[lookIndex].task_accept_id,
                pagesize: 20,
                search: 1
            })
        }
    },
};